package com.teach.customer.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.common.bean.PageVo;
import com.common.bean.QueryCondition;
import com.common.bean.PageEntity;

import com.common.utils.BeanUtil;
import com.teach.customer.model.DO.CommissionDO;
import com.teach.customer.model.po.ImsHcCmsCommissionPO;
import com.teach.customer.dao.ImsHcCmsCommissionMapper;
import com.teach.customer.model.po.ImsHcCmsCustomerPO;
import com.teach.customer.model.po.ImsHcCmsLoupanPO;
import com.teach.customer.model.vo.FollowVO;
import com.teach.customer.service.ImsHcCmsCommissionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.teach.customer.service.ImsHcCmsCustomerService;
import com.teach.sys.dao.dict.DictDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;

import javax.annotation.Resource;

/**
 * <p>
 *   服务实现类
 * </p>
 * @version 1.0
 * @author hzz
 * @since 2021-04-21
 */
@Service
public class ImsHcCmsCommissionServiceImpl extends ServiceImpl<ImsHcCmsCommissionMapper, ImsHcCmsCommissionPO> implements ImsHcCmsCommissionService {

    @Resource
    private DictDao dictDao;
    @Autowired
    private ImsHcCmsCustomerService imsHcCmsCustomerService;
    @Autowired
    private ImsHcCmsCounselorServiceImpl imsHcCmsCounselorService;
    @Autowired
    private ImsHcCmsLoupanServiceImpl imsHcCmsLoupanService;

    public PageVo queryPage(QueryCondition params,QueryWrapper<ImsHcCmsCommissionPO> queryWrapper){
        IPage<ImsHcCmsCommissionPO> page = this.page(
            new PageEntity<ImsHcCmsCommissionPO>().getPage(params),queryWrapper);
        List<ImsHcCmsCommissionPO> records = page.getRecords();
        List<FollowVO> vo= new ArrayList<>();
        for (ImsHcCmsCommissionPO po:records){
            FollowVO followVO=new FollowVO();
            BeanUtil.copy(po,followVO);
            followVO.setCommissionId(po.getId());
            ImsHcCmsCustomerPO byId = imsHcCmsCustomerService.getById(po.getCusid());
            if (byId!=null){
                followVO.setCustomerName(byId.getRealname());
            }
            ImsHcCmsLoupanPO loupan = imsHcCmsLoupanService.getById(po.getLoupanid());
            if (loupan!=null){
                followVO.setLoupanName(loupan.getTitle());
            }
            vo.add(followVO);
        }
        return new PageVo(vo,page);
    }
    public PageVo genJinPage(QueryCondition params, CommissionDO commissionDO){
        IPage<ImsHcCmsCommissionPO> page = new PageEntity<ImsHcCmsCommissionPO>().getPage(params);
        List<FollowVO> vo= baseMapper.genJinList(commissionDO);
        return new PageVo(vo,page);
    }
    public List<String> followList(){
        return dictDao.findLabelByType("follow_status");
    }
}


